package cn.dengta.webapp.trade.entity;

import java.util.List;

import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.trade.model.GroupVipLevel;
import cn.dengta.webapp.trade.vo.RechargeProductVO;
import cn.dengta.webapp.user.model.GroupVipRule;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 群VIP 权益配置
 *
 * @author xy
 * @since 2022-07-11
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName(value = "tr_group_vip_equity", autoResultMap = true)
public class GroupVipEquity extends TimeBasedEntity {

	private static final long serialVersionUID = 1L;
	/** 权益名称 */
	private String equityName;
	/** 群VIP等级 1=VIP; 2=SVIP; 3=SSVIP; 4=SUPER VIP; 5=TOP VIP */
	private GroupVipLevel level;
	/** 权益图片 */
	private String image;
	/** 排序 */
	private Integer sort;
	/** 权益 */
	@TableField(value = "equity", typeHandler = JacksonTypeHandler.class)
	private JSONObject equity;
	/** 扩展数据 */
	@TableField(value = "extend", typeHandler = JacksonTypeHandler.class)
	private JSONObject extend;
	/** 业务状态 -1=禁用； 1=启用 */
	protected Integer status;

	@TableField(exist = false)
	private List<RechargeProductVO> productVOS;

	/**
	 * 获取群VIP配置信息
	 */
	public GroupVipRule getGroupVipConfig() {
		return this.equity == null ? null : this.equity.toJavaObject(GroupVipRule.class);
	}

	public List<ExtendGroupVipVO> getExtendGroupVipVO() {
		return this.getExtend() == null ? null : this.getExtend().getJSONArray("configs").toJavaList(ExtendGroupVipVO.class);
	}

	public static final String EQUITY_NAME = "equity_name";
	public static final String LEVEL = "level";
	public static final String IMAGE = "image";
	public static final String SORT = "sort";
	public static final String EQUITY = "equity";
	public static final String EXTEND = "extend";
	public static final String STATUS = "status";

	@Setter
	@Getter
	public static class ExtendGroupVipVO {

		/** icon图片 */
		private String icon;
		/** 对应 @see GroupVipRule 注解内容 @JSONField(name = "gm") */
		private String name;

	}

}
